package com.ruoyi.media.mpQrcodeData.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.zxing.oned.UPCAReader;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.media.mpQrcode.domain.MediaMpQrcodeLink;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.media.mpQrcodeData.domain.vo.MediaMpQrcodeDataVo;
import com.ruoyi.media.mpQrcodeData.domain.bo.MediaMpQrcodeDataBo;
import com.ruoyi.media.mpQrcodeData.service.IMediaMpQrcodeDataService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信群二维码数据
 *
 * @author dqw
 * @date 2023-04-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/media/mpQrcodeData")
public class MediaMpQrcodeDataController extends BaseController {

    private final IMediaMpQrcodeDataService iMediaMpQrcodeDataService;

    /**
     * 查询微信群二维码数据列表
     */
    @SaCheckPermission("media:mpQrcodeLink:list")
    @GetMapping("/list")
    public TableDataInfo<MediaMpQrcodeDataVo> list(MediaMpQrcodeDataBo bo, PageQuery pageQuery) {
        return iMediaMpQrcodeDataService.queryPageList(bo, pageQuery);
    }


    /**
     * 修改二维码查看状态
     */
    @SaCheckPermission("media:mpQrcodeLink:list")
    @GetMapping("/setLookStatus/{id}")
    public R<?> setLookStatus(@PathVariable String id) {
        MediaMpQrcodeDataVo  mediaMpQrcodeDataVo =  iMediaMpQrcodeDataService.queryById(id);
        MediaMpQrcodeDataBo mediaMpQrcodeDataBo = new MediaMpQrcodeDataBo();
        BeanUtils.copyProperties(mediaMpQrcodeDataVo,mediaMpQrcodeDataBo); //复制属性到bo
        mediaMpQrcodeDataBo.setIsUse(1);
        return R.ok(iMediaMpQrcodeDataService.updateByBo(mediaMpQrcodeDataBo));
    }


    /**
     * 导出微信群二维码数据列表
     */
    @SaCheckPermission("media:mpQrcodeLink:export")
    @Log(title = "微信群二维码数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MediaMpQrcodeDataBo bo, HttpServletResponse response) {
        List<MediaMpQrcodeDataVo> list = iMediaMpQrcodeDataService.queryList(bo);
        ExcelUtil.exportExcel(list, "微信群二维码数据", MediaMpQrcodeDataVo.class, response);
    }

    /**
     * 获取微信群二维码数据详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("media:mpQrcodeLink:query")
    @GetMapping("/{id}")
    public R<MediaMpQrcodeDataVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iMediaMpQrcodeDataService.queryById(id));
    }

    /**
     * 新增微信群二维码数据
     */
    @SaCheckPermission("media:mpQrcodeLink:add")
    @Log(title = "微信群二维码数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MediaMpQrcodeDataBo bo) {
        return toAjax(iMediaMpQrcodeDataService.insertByBo(bo));
    }

    /**
     * 修改微信群二维码数据
     */
    @SaCheckPermission("media:mpQrcodeLink:edit")
    @Log(title = "微信群二维码数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MediaMpQrcodeDataBo bo) {
        return toAjax(iMediaMpQrcodeDataService.updateByBo(bo));
    }

    /**
     * 删除微信群二维码数据
     *
     * @param ids 主键串
     */
    @SaCheckPermission("media:mpQrcodeLink:remove")
    @Log(title = "微信群二维码数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iMediaMpQrcodeDataService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
